//
//  AnimationView.swift
//  SwiftStudy
//
//  Created by mybox_1027@sina.com on 16/4/16.
//  Copyright © 2016年 mybox_1027@sina.com. All rights reserved.
//

import Foundation

class AnimationView: UIViewController {
    
    @IBOutlet weak var viewSpacingContraint: NSLayoutConstraint!
    @IBOutlet weak var blueConstraint: NSLayoutConstraint!
    
    @IBOutlet weak var mSwtich: UISwitch!
    
    func updateViewConstraintsWhentTap(){
        if mSwtich.on
        {
            self.viewSpacingContraint.constant = 8.0;
            self.blueConstraint.priority = UILayoutPriorityDefaultHigh + 1;
        }
        else
        {
            self.viewSpacingContraint.constant = self.view.frame.size.width;
            self.blueConstraint.priority = UILayoutPriorityDefaultHigh - 1;
        }
    }
    
    
    @IBAction func switchTap(sender: AnyObject) {
        self.view.layoutIfNeeded()
        UIView.animateWithDuration(1.0) { 
            self.updateViewConstraintsWhentTap()
            self.view.layoutIfNeeded()
        }
    }
    
    override func viewDidLoad() {
        self.updateViewConstraintsWhentTap()
    }
}